<?php

/**
 * 用户
 *
 * @author haifeng.wu
 */

class Application_Model_User extends Application_Model_Common
{
    /**
     * 表名
     *
     * @var string
     */
    protected $_name= 'front_user';

    /**
     * 构造函数
     * 
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 删除用户
     * 
     * @param  array $ids
     * @return integer
     */
    public function deleteByIds(array $ids)
    {
        if (!empty($ids)) {
            $userRoleModel = new Application_Model_UserRole();
            $userRoleProductModel = new Application_Model_UserRoleProduct();
            $this->getAdapter()->getConnection()->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
            $this->getAdapter()->query("start transaction;");
            try{
                $userRoleProductModel->delete("`userId` IN (" . implode(',', $ids) . ")");
                $userRoleModel->delete("`userId` IN (" . implode(',', $ids) . ")");
                $this->delete("`id` IN (" . implode(',', $ids) . ")");
                $this->getAdapter()->query("commit;");
            } catch (Exception $e) {
                $this->getAdapter()->query("rollback;");
                throw new Zend_Exception($e->getMessage());
            }
        }
    }

 
}